import React from 'react';
import {
  Icon, Tabs,NavBar
} from 'antd-mobile';
import axios from "axios";
import TabIndex from './TabIndex';

import '../css/stage2.css';

axios.defaults.baseURL = '/app'
axios.defaults.headers.post['Content-Type'] = 'application/json';

export default class Demo extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      data: props.data,
      arr:[],
      imgHeight: 400
    }
  }

  componentDidMount() {
    
  }
  componentWillMount() {
    var query = window.location.href;
    var ps = query.split('?')[1];
    var pid = ps.split('&')[0].split('=')[1];
    var pname = decodeURI(ps.split('&')[1].split('=')[1]);
    var url = "/menu/pid/" + pid;
    axios.get(url).then(res => {
      console.log(res.data);
      this.setState({
        data: res.data,
      });
    });
    this.props.changeTitle(pname);
  }

  toBackHomePage(){
    window.location.href = 'http://localhost:8000';
  }
  renderContent = tab =>
  (<div>
    <TabIndex code={tab.code} category={tab.category} memo={tab.memo}/>
  </div>);

  render() {
    return (<div style={{ marginBottom: 30 }}>
      {/* <SearchBar placeholder="搜索" /> */}
      <div>
    <NavBar
      leftContent={[
        <Icon type="left"/>,
        <span>返回</span>
      ]}
      mode="light"
      onLeftClick={() => history.go(-1)}
      rightContent={[
        <span>首页</span>,
        <Icon key="0" type="right" style={{ marginRight: '16px' }} onClick={() => this.toBackHomePage()}/>
      ]}
    ></NavBar>
  </div>
      <Tabs tabs={this.state.data} renderTab={tab => tab.name}>
        {this.renderContent}
      </Tabs>
    </div>);
  }
}
